package com.auto.api.common.enums;

/**
 * Description: 异常码
 *
 * @author liangshf
 * @date 2019-03-04
 */
public enum ResultCode implements ResultEnum<String> {
    /**
     * 0-执行成功
     */
    SUCCESS("0", "操作成功"),
    /**
     * -1-执行失败
     */
    FAIL("-1", "操作失败"),
    DATA_NOT_EXIST("1", "数据不存在"),
    /**
     * 1000-业务异常
     */
    BUSINESS_ERROR("1000", "业务异常"),
    /**
     * 10000-服务异常
     */
    SERVICE_ERROR("10000", "服务异常");

    private String code;
    private String desc;

    ResultCode(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }


    /**
     * 根据code值换取中文提示信息
     * @param code 错误码
     */
    public static ResultCode enumValueOf(String code) {
        for (ResultCode codeEnum : ResultCode.values()) {
            if (codeEnum.getCode().equals(code)) {
                return codeEnum;
            }
        }
        return null;
    }


    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

}
